using Microsoft.AspNetCore.Http;
using KnowledgeQA.Models.DTOs;
using KnowledgeQA.Models.Entities;

namespace KnowledgeQA.Services.Interfaces
{
    /// <summary>
    /// 文档服务接口
    /// </summary>
    public interface IDocumentService
    {
        /// <summary>
        /// 获取文档列表
        /// </summary>
        /// <param name="request">查询请求</param>
        /// <returns>分页文档列表</returns>
        Task<PagedResponse<DocumentDTO>> GetDocumentsAsync(DocumentQueryRequest request);

        /// <summary>
        /// 根据ID获取文档
        /// </summary>
        /// <param name="id">文档ID</param>
        /// <returns>文档信息</returns>
        Task<DocumentDTO?> GetDocumentByIdAsync(int id);

        /// <summary>
        /// 创建文档
        /// </summary>
        /// <param name="request">创建请求</param>
        /// <returns>创建的文档</returns>
        Task<DocumentDTO> CreateDocumentAsync(CreateDocumentRequest request);

        /// <summary>
        /// 更新文档
        /// </summary>
        /// <param name="id">文档ID</param>
        /// <param name="request">更新请求</param>
        /// <returns>更新后的文档</returns>
        Task<DocumentDTO> UpdateDocumentAsync(int id, UpdateDocumentRequest request);

        /// <summary>
        /// 删除文档
        /// </summary>
        /// <param name="id">文档ID</param>
        /// <returns>是否成功</returns>
        Task<bool> DeleteDocumentAsync(int id);

        /// <summary>
        /// 上传文档文件
        /// </summary>
        /// <param name="file">文件</param>
        /// <param name="request">创建请求</param>
        /// <returns>上传结果</returns>
        Task<DocumentDTO> UploadDocumentAsync(IFormFile file, CreateDocumentRequest request);

        /// <summary>
        /// 批量上传文档
        /// </summary>
        /// <param name="files">文件列表</param>
        /// <param name="categoryId">分类ID</param>
        /// <returns>上传结果列表</returns>
        Task<List<DocumentDTO>> BatchUploadDocumentsAsync(IEnumerable<IFormFile> files, int? categoryId = null);

        /// <summary>
        /// 处理文档（提取内容并分块）
        /// </summary>
        /// <param name="documentId">文档ID</param>
        /// <returns>处理结果</returns>
        Task<bool> ProcessDocumentAsync(int documentId);

        /// <summary>
        /// 重新处理文档
        /// </summary>
        /// <param name="documentId">文档ID</param>
        /// <returns>处理结果</returns>
        Task<bool> ReprocessDocumentAsync(int documentId);

        /// <summary>
        /// 获取文档统计信息
        /// </summary>
        /// <returns>统计信息</returns>
        Task<DocumentStats> GetDocumentStatsAsync();
    }

    /// <summary>
    /// 文档统计信息
    /// </summary>
    public class DocumentStats
    {
        /// <summary>
        /// 总文档数
        /// </summary>
        public int TotalDocuments { get; set; }

        /// <summary>
        /// 已处理文档数
        /// </summary>
        public int ProcessedDocuments { get; set; }

        /// <summary>
        /// 处理中文档数
        /// </summary>
        public int ProcessingDocuments { get; set; }

        /// <summary>
        /// 失败文档数
        /// </summary>
        public int FailedDocuments { get; set; }

        /// <summary>
        /// 总文件大小（字节）
        /// </summary>
        public long TotalFileSize { get; set; }

        /// <summary>
        /// 按类型统计的文档数
        /// </summary>
        public Dictionary<string, int> DocumentsByType { get; set; } = new Dictionary<string, int>();

        /// <summary>
        /// 按状态统计的文档数
        /// </summary>
        public Dictionary<string, int> DocumentsByStatus { get; set; } = new Dictionary<string, int>();
    }
} 